package com.softer.chengxin.score.dao;

import com.softer.chengxin.common.domin.Page;
import com.softer.chengxin.score.dao.provider.ScoreManagerDaoProvider;
import com.softer.chengxin.score.entity.ScoreRecord;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Gong Zhiyang
 * @date 2018/10/12
 */
@Mapper
@Repository
public interface ScoreManagerDao {
    /**
     * 获取企业信用得分
     *
     * @param id   企业Id
     * @param year 年度
     * @return 得分情况
     */
    @Select("select a.jc_01 as jc01,a.jc_02 as jc02,a.jc_03 as jc03,a.jc_04 as jc04,a.jc_05 as jc05,a.jc_06 as jc06,a.jc_07 as jc07," +
            "a.yl_01 as yl01,a.yl_02 as yl02,a.yl_03 as yl03,a.yl_04 as yl04,a.yl_05 as yl05,a.yl_06 as yl06,a.yl_07 as yl07,a.yl_08 as yl08," +
            "a.fm_01 as fm01,a.fm_02 as fm02,a.fm_03 as fm03,a.fm_04 as fm04,a.fm_05 as fm05,a.fm_06 as fm06,a.fm_07 as fm07," +
            "a.all_score as allScore,a.poguid as poguid,a.dj,a.`year`,b.`name` AS qyName from score_record a LEFT JOIN company_base_info b ON a.poguid=b.id where a.poguid=#{id} and a.year=#{year}")
    ScoreRecord getScore(@Param("id") Integer id, @Param("year") String year);

    /**
     * 增加企业得分详情数据
     * 企业注册时，初始化企业得分记录
     *
     * @param scoreRecord 详情数据
     * @return 增加结果
     */
    @Insert("INSERT INTO score_record(jc_01,jc_02,jc_03,jc_04,jc_05,jc_06,jc_07,all_score,poguid,gmt_create,gmt_modified,dj,year) " +
            "VALUES(#{sr.jc01},#{sr.jc02},#{sr.jc03},#{sr.jc04},#{sr.jc05},#{sr.jc06},#{sr.jc07},#{sr.allScore},#{sr.poguid},now(),now(),#{sr.dj},#{sr.year})")
    int addScoreRecord(@Param("sr") ScoreRecord scoreRecord);

    /**
     * 获取企业信用等级数量
     *
     * @param scoreRecord 查询实体
     * @return 数量
     */
    @SelectProvider(type = ScoreManagerDaoProvider.class, method = "getScoreRecordNum")
    int getScoreRecordNum(@Param("scoreRecord") ScoreRecord scoreRecord);

    /**
     * 获取企业信用等级列表
     *
     * @param page        页面实体
     * @param scoreRecord 查询实体
     * @return 列表
     */
    @SelectProvider(type = ScoreManagerDaoProvider.class, method = "getScoreRecordList")
    List<ScoreRecord> getScoreRecordList(@Param("page") Page page, @Param("scoreRecord") ScoreRecord scoreRecord);
}
